package com.he.security;

import com.alibaba.fastjson2.JSON;
import com.he.utils.AuthExceptionUtil;
import com.he.utils.WebUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import jakarta.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author He
 * @version 1.0
 * @Date 2023/9/6 16:16
 * @Desc 用于处理访问拒绝异常实现AccessDeniedHandler接口，当用户权限不足时，会进入AccessDenieHandler进行处理,会将无权限信息返回给前端
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        accessDeniedException.printStackTrace();
//        WebUtils.renderString(response, JSON.toJSONString(AuthExceptionUtil.getAccessExceptionType(accessDeniedException)));
    }
}
